import java.util.*;

public class A_2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<List<Integer>> list = new ArrayList<>();
        sc.nextLine();
        for (int i = 0; i < n; i++) {
            String str = sc.nextLine();
            Scanner s = new Scanner(str);
            List<Integer> l = new ArrayList<>();
            while(s.hasNextInt()){
                l.add(s.nextInt());
            }
            list.add(l);
        }
        System.out.println(canVisitAllRooms(list));
    }
    static Set<Integer> set,guo;
    static public boolean canVisitAllRooms(List<List<Integer>> rooms) {
        set = new HashSet<>();guo = new HashSet<>();
        dfs(rooms,0);
        if (!set.contains(0))
            return set.size()==rooms.size()-1;
        else return set.size()==rooms.size();
    }
    static void dfs(List<List<Integer>> rooms, int now) {
        guo.add(now);
        List<Integer> list = rooms.get(now);
        set.addAll(list);
        for (Integer integer : new ArrayList<>(set))
            if (!guo.contains(integer))
                dfs(rooms, integer);
    }

}